<?php

require_once('include/classes/commons/DBI.php');

$dbh = new DBI('mysql', 'localhost', '3306', 'gomarche', 'gomma', 'gomarche', 'Errore di connessione al DB');

//$sql = "SELECT news_id, title, abstract FROM tbl_news WHERE date_created = DATE_FORMAT('%Y-%m-%d', NOW()) ORDER BY news_id DESC";
//$sql = "SELECT news_id, title, abstract FROM tbl_news WHERE date_created = NOW() ORDER BY news_id DESC";
//$sql = "SELECT news_id, title, abstract FROM tbl_news ORDER BY news_id DESC";

$sql = "SELECT news_id, title, abstract FROM tbl_news WHERE CURDATE() = date_created ORDER BY news_id DESC";

$pstmt = $dbh->prepare($sql);
$pstmt->setFetchMode(PDO::FETCH_ASSOC);

$news = array();

if ( $pstmt->execute() ) {
    $news = $pstmt->fetchAll();
}

header('Content-type: application/xml');

echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n
<rss version=\"2.0\">\n
<channel>\n 
<title>GoMarche</title>\n
<link>http://www.gomarche.it</link>\n
<description>Quotidiano OnLine delle Marche</description>\n
<language>IT-it</language>\n
<image>\n
    <url>http://www.gomarche.it/images/gomarche_logo_feed.jpg</url>\n
    <title>GoMarche</title>\n
    <link>http://www.gomarche.it</link>\n
    <description>Quotidiano OnLine delle Marche</description>\n
</image>\n";

foreach ( $news AS $newsItem ) {
    #$data = date ( "D, d M Y H:i:s", strtotime ( $result[$field_date] ) )." GMT";
  echo "<item>\n
    <title><![CDATA[" . $newsItem['title'] . "]]></title>\n
    <pubDate>" . ucwords(strftime("%a, %d %b %Y %T")) . " GMT</pubDate>\n
    <link>http://www.gomarche.it/news.php?newsId=" . $newsItem['news_id'] . "</link>\n
    <description><![CDATA[" . $newsItem['abstract'] . "]]></description>\n
</item>\n"; 
} 
echo "</channel>\n"; 
echo "</rss>"; 
?>
